let id = 0

export default class Dep {
  constructor () {
    this.id = id++
    this.subs = []
  }

  addSub (watcher) {
    this.subs.push(watcher)
  }

  depend () {
    // this.subs.push(Dep.target)

    if (Dep.target) {
      Dep.target.addDep(this)
    }
  }

  notify () {
    for (let i = 0, l = this.subs.length; i < l; i++) {
      this.subs[i].update()
    }
  }
}

Dep.target = null
let stack = []
export function pushTarget (watcher) {
  stack.push(watcher)
  Dep.target = watcher
}
export function popTarget () {
  stack.pop()
  Dep.target = stack[stack.length - 1]
}